#include <sxQViewportFrameLayout.h>

Sx::QtInterface::QViewportFrameLayout::QViewportFrameLayout(QWidget* parent) : QWidget(parent) {
	this->focusedViewport = nullptr;
}

Sx::QtInterface::QViewportFrameLayout::~QViewportFrameLayout() {
	
}

void Sx::QtInterface::QViewportFrameLayout::onFocusedViewportChange(QViewportFrame* viewport) {
	this->focusedViewport = viewport;
}

bool Sx::QtInterface::QViewportFrameLayout::maximizeSelectedViewport(bool maximize) {
	if ( this->focusedViewport == nullptr ) {
		std::cout << "[QViewportFrameLayout:maximizeSelectedViewport] Warning: No Viewport selected to maximize." << std::endl;
		return false;
	}

	//--------------------------------------------------------------------------
	// If maximize is equal to false, restore all of the viewports.
	//--------------------------------------------------------------------------
	if ( maximize == false ) {
		for ( unsigned int i = 0; i < this->viewportFrames.size(); i++ )
			this->viewportFrames[i]->setVisible(true);
		return true;
	}

	//--------------------------------------------------------------------------
	// If maximize is equal to true then hide all of the other viewports. Qt is
	// specifically useful in this regard because by just setting the other
	// viewports visibility to false, the only remaining visible viewport
	// is maximized to the parent.
	//--------------------------------------------------------------------------
	for ( unsigned int i = 0; i < this->viewportFrames.size(); i++ ) {
		if ( this->viewportFrames[i] == this->focusedViewport )
			this->viewportFrames[i]->setVisible(true);
		else this->viewportFrames[i]->setVisible(false);
		this->viewportFrames[i]->update();
	}

	this->repaint();
	return true;
}

void Sx::QtInterface::QViewportFrameLayout::deselectAllViewports() {
	for ( unsigned int i = 0; i < this->viewportFrames.size(); i++ )
		this->viewportFrames[i]->getController()->deselect();
}
